var app = global.app;
var filePath = app.filePath;
var child_process = require('child_process');
var spawn = child_process.spawn;

module.exports = function (fileName, resizeName, width, callback) {
    var args = [];
    args.push('-resize');
    args.push(width + 'x');
    args.push('-quality');
    args.push('100');
    args.push('+profile');
    args.push('"*"');
    args.push(filePath + fileName);
    args.push(filePath + resizeName);
    var convert = spawn('convert', args);
    convert.stderr.on('data', function (data) {
        callback({
            'error':1,
            'message':data.toString()
        })
    });
    convert.on('exit', function (code) {
        callback({
            'error':0,
            'data':{
                'fileName':resizeName
            }
        });
    });
};